<template>
  <div
    v-loading="loading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)"
  >
    <el-row class="padding-sm">
      <el-col :span="24"
        ><div class="flex-between items-center">
          <div class="flex">
            <el-select
              v-model="select_Search"
              slot="prepend"
              size="mini"
              placeholder="请选择"
            >
              <el-option label="小吃" value="1"></el-option>
              <el-option label="饮料" value="2"></el-option>
              <el-option label="牛排" value="3"></el-option>
              <el-option label="披萨" value="4"></el-option>
            </el-select>
            <el-input
              placeholder="请输入内容"
              size="mini"
              v-model="Search_content"
              class="input-with-select"
            >
              <el-button
                slot="append"
                size="mini"
                type="primary"
                icon="el-icon-search"
                @click="Search_contents"
              ></el-button>
            </el-input>
          </div>
          <router-link :to="{path:'/Steak-series/add',query:{id:0}}">
            <el-button type="primary" size="mini" round plain>
              添加商品
            </el-button>
          </router-link>
        </div></el-col
      >
    </el-row>
    <el-table :data="tabSopp" style="width: 100%">
      <el-table-column label="上架时间" prop="cretime" />
      <el-table-column label="名称" prop="spname" />
      <el-table-column label="样图">
        <template slot-scope="scopes">
          <img
            :src="scopes.row.image"
            style="width: 80px; height: 80px"
            alt=""
            srcset=""
          />
        </template>
      </el-table-column>
      <el-table-column label="商品类目" prop="classification" width="100px" />
      <el-table-column label="价格" prop="price" width="100px" />
      <el-table-column label="月售" prop="Monthly_sales" width="100px" />
      <el-table-column label="操作" align="right" width="220px">
        <template slot-scope="scopes">
          <el-button size="mini" @click="setList(scopes.row)" :disabled="!scopes.row.operation">编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="DeleteList(scopes.row)"
            v-if="scopes.row.operation"
            >下架</el-button
          >
          <el-button
            size="mini"
            type="success"
            @click="putList(scopes.row)"
            v-else
            >上架</el-button
          >
        </template>
      </el-table-column>
      <!-- </el-table-column> -->
    </el-table>
    <el-pagination
      style="text-align: center; margin-top: 10px"
      background
      layout="prev, pager, next"
      :total="total"
      :current-page="currentnum"
      :hide-on-single-page="true"
      @current-change="currentchange"
    >
    </el-pagination>
  </div>
</template>

<script>
import business from "@/utils/business";
import deldete from "@/utils/deldete";
export default {
  data() {
    return {
      loading: true, //页面数据加载
      tabSopp: [],
      // 搜索内容
      Search_content: "",
      select_Search: "",
      currentnum: 1, //当前页数
      pagenum: 0, //分页
      total: 0, //总条数
    };
  },
  created() {
    this.paging();
  },

  methods: {
    // 编辑商品
    setList(index, row) {
      this.$router.push({ name: "SteakAdd", query: { id: index._id } });
    },
    // 下架商品
    DeleteList(data) {
      deldete
        .deshoplist(data)
        .then((res) => {
          if (res.status == 200) {
            this.paging();
          } else {
            this.$message.warning(res.data.msg);
          }
        })
        .catch((error) => {
          this.$message.error(error);
          console.log("error", error);
        });
      // this.tabSopp = this.tabSopp.filter((liten) => {liten._id !== index._id});
    },
    // 上架商品
    putList(data) {},
    // 搜索商品
    Search_contents() {
      console.log("搜索内容:", this.Search_content);
    },
    //商品列表分页
    paging() {
      let pagenum = this.pagenum;
      business
        .sppaging({ pagenum })
        .then((res) => {
          this.tabSopp = res.data.data.result;
          this.total = res.data.data.total;
          this.loading = false;
        })
        .catch((error) => {
          console.log("出错了：", error);
        });
    },
    currentchange(res) {
      this.pagenum = res - 1;
      this.paging();
    },
  },
};
</script>

<style lang="less" scoped>
</style>